﻿using System;
using System.Collections.Generic;
using System.Resources;
using System.Text;
using com.lover.astd.common.config;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;
using com.lover.astd.common.model.building;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.common.logicexe.hero
{
    public class HeroWashExe : ExeBase
    {
        public HeroWashExe() { _name = ConfigStrings.S_HeroWash; _readable = ConfigStrings.SR_HeroWash; }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();
            if (conf.ContainsKey(ConfigStrings.wash_hero) && conf[ConfigStrings.wash_hero] != "")
            {
                int wash_hero = 0;
                if (Int32.TryParse(conf[ConfigStrings.wash_hero], out wash_hero))
                {
                    string wash_attrib = conf[ConfigStrings.wash_attrib];
                    if (wash_attrib.Length < 3)
                    {
                        for (int i = 0; i < 3 - wash_attrib.Length; i++) wash_attrib += "0";
                    }

                    HeroMgr mgr = ServiceFactory.getHeroManager();

                    if (wash_hero == 0 || wash_attrib == "")
                    {
                        logInfo("没有可洗的武将");
                        return next_hour();
                    }
                    int[] attribtes = new int[3] { 0, 0, 0 };
                    int wash_result = mgr.startWash(_proto, _logger, _user, wash_hero, wash_attrib, true, getCreditAvailable(), 20, ref attribtes);
                    if (wash_result == 1) { logInfo("武将已经洗属性完毕, 将在1小时候再次检查"); return 60 * 60 * 1000; }
                    else if (wash_result == 2) { logInfo("洗将出错, 半小时后继续"); return 30 * 60 * 1000; }
                    else if (wash_result == 3) { logInfo("条件不足, 今天不再洗属性"); return next_day(); }
                    refreshUi();
                    return next_day();
                }
            }
            return immediate();
        }
    }
}
